package com.study;

import com.study.annotation.EnableMyConfig;
import com.study.annotation.EnableMyConfig2;
import com.study.entity.User;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;

@SpringBootApplication
//@Configuration
//@EnableAutoConfiguration
@EnableMyConfig
@EnableMyConfig2
public class RestTemplateApp {


    public static void main(String[] args) {
        SpringApplication springApplication = new SpringApplication(RestTemplateApp.class);
        ConfigurableApplicationContext applicationContext = springApplication.run(args);

        //@SpringBootApplication 包含@EnableAutoConfiguration， @EnableAutoConfiguration 开启自动扫描装配Bean, 所以有 @SpringBootApplication时，可以获取到user实例
        //当使用@Configuration + @EnableAutoConfiguration 需要加上@Import 配置类
        User user = (User) applicationContext.getBean("user");
        System.out.println(user.toString());

        User user2 = (User) applicationContext.getBean("user2");
        System.out.println(user2.toString());
    }
}
